package com.yaoayao.mall.mq.controller;

import com.yaoayao.mall.common.result.Result;
import com.yaoayao.mall.mq.config.DeadLetterMqConfig;
import com.yaoayao.mall.mq.config.DelayMqConfig;
import com.yaoayao.mall.rabbit.service.RabbitService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: peiyao
 * @date: 2024/4/18 18:49
 * @description:
 */

@RestController
@RequestMapping("/api/mq")
public class MqSendController {

    @Autowired
    private RabbitService rabbitService;
    //发消息
    @GetMapping("/sendMessage")
    public Result sendMessage(String message){
        rabbitService.sendMessage("exchange111","routingKey222",message);
        return Result.ok();
    }

    //发消息
    @GetMapping("/sendMessage2")
    public Result sendMessage2(String message){
        rabbitService.sendMessage("exchange222","routingKey222",message);
        return Result.ok();
    }

    //发延迟消息  （基于死信）
    @GetMapping("/sendDeadLetterMessage")
    public Result sendDeadLetterMessage(String message){

        rabbitService.sendDeadLetterMessage(DeadLetterMqConfig.exchange_dead,
                DeadLetterMqConfig.routing_dead_1,message,12);

        return Result.ok();
    }
    //发送延迟消息 （基于延迟插件的）
    @GetMapping("/sendDelayMessage")
    public Result sendDelayMessage(String message){
        rabbitService.sendDelayMessage(DelayMqConfig.exchange_delay,
                DelayMqConfig.routing_delay,message,9);
        return Result.ok();
    }
}
